<html>
<!-- =====================================================================

  File:      usp_OrdersList.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Store Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body class="NormalIndent">
        <h1>
            "usp_OrdersList" Stored Procedure
        </h1>
        <b>Description:</b>
        <P>
            This stored procedure accepts a CustomerID as input and returns a list of all
            the user's orders in the Orders table. This procedure is used on the
            OrdersList.aspx page.
        </P>
        <b>Definition:</b>
<pre style="background-color:white">
<span style="color: #0000FF"><strong>CREATE</strong></span> Procedure usp_OrdersList
<span style="color: #4444FF">(</span>
    @CustomerID <span style="color: #2040a0"><strong>int</strong></span><span style="color: #4444FF">,</span>
	@Culture <span style="color: #2040a0"><strong>nvarchar</strong></span><span style="color: #4444FF">(</span>10<span style="color: #4444FF">)</span>

<span style="color: #4444FF">)</span>
<span style="color: #0000FF"><strong>AS</strong></span>

<span style="color: #0000FF"><strong>SELECT</strong></span>  
    SOH.SalesOrderID<span style="color: #4444FF">,</span>
    dbo.ConvertCurrency<span style="color: #4444FF">(</span>sum<span style="color: #4444FF">(</span>SOD.OrderQty<span style="color: #4444FF">*</span>SOD.UnitPrice<span style="color: #4444FF">)</span><span style="color: #4444FF">,</span> @Culture<span style="color: #4444FF">)</span>.ToString<span style="color: #4444FF">(</span><span style="color: #4444FF">)</span> <span style="color: #0000FF"><strong>as</strong></span> OrderTotal<span style="color: #4444FF">,</span>
    SOH.OrderDate<span style="color: #4444FF">,</span> 
    SOH.ShipDate<span style="color: #4444FF">,</span>
	SCM.StatusMessage

<span style="color: #0000FF"><strong>FROM</strong></span>    
    Sales.SalesOrderHeader <span style="color: #0000FF"><strong>AS</strong></span> SOH
  INNER JOIN Sales.SalesOrderDetail <span style="color: #0000FF"><strong>AS</strong></span> SOD <span style="color: #0000FF"><strong>ON</strong></span> SOH.SalesOrderID <span style="color: #4444FF">=</span> SOD.SalesOrderID
  INNER JOIN dbo.StatusCodeMessage <span style="color: #0000FF"><strong>AS</strong></span> SCM <span style="color: #0000FF"><strong>ON</strong></span> SOH.Status <span style="color: #4444FF">=</span> SCM.StatusCode

<span style="color: #0000FF"><strong>GROUP BY</strong></span>    
    SOH.CustomerID<span style="color: #4444FF">,</span> 
    SOH.SalesOrderID<span style="color: #4444FF">,</span> 
    SOH.OrderDate<span style="color: #4444FF">,</span> 
    SOH.ShipDate<span style="color: #4444FF">,</span>
	SCM.StatusMessage
HAVING  
    SOH.CustomerID <span style="color: #4444FF">=</span> @CustomerID;


</pre>
        <b>Database Tables Used: </b>
        <P>
            <i>SalesOrderHeader:</i>
        &nbsp;The SalesOrderHeader table contains the header information about all the orders in
        the system (i.e., all sales transactions that are actually completed. Users must check out
        their cart to place an order in the system). When an order is created, an entry
        is made in the SalesOrderHeader table with the CustomerID, OrderDate and ShipDate. Then,
        any information about the products in the order is added to the SaleOrderDetail
        table as discussed below. Note that if no OrderDate or ShipDate is provided,
        the current date is entered as default.
        <p>
            <i>SalesOrderDetail:</i>
        &nbsp;The SalesOrderDetail table contains detailed product information for each
        order in the system. For each product in an order, an entry is made into the
        SalesOrderDetail table containing the ProductID, Quantity and current UnitCost of
        the item. There is a many to one relationship between SalesOrderDetail table and
        the SalesOrderHeader table. Note the primary key in the table is both SalesOrderID and
        LineNumber (since those two columns are the minimum required to guarantee
        uniqueness of a record).
        <p>
            <IMG src="1x1.gif" width="25"> <IMG src="../docs/images/SalesOrderHeader-Detail.gif" width="585" height="455">
 
    </body>
</html>
